package com.httpdemo.http_teaching_server.controller;

import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.util.Map;

@RestController
@RequestMapping("/upload")
public class FileUploadController {

    /* 1️⃣ 单文件上传 */
    @PostMapping("/single")
    public Map<String, Object> single(@RequestPart("file") MultipartFile file) throws IOException {
        return Map.of(
                "type", "single",
                "originalFilename", file.getOriginalFilename(),
                "size", file.getSize(),
                "bytesReceived", file.getBytes().length
        );
    }

    /* 2️⃣ 多文件上传 */
    @PostMapping("/multi")
    public Map<String, Object> multi(@RequestPart("files") MultipartFile[] files) {
        return Map.of(
                "type", "multi",
                "count", files.length
        );
    }
}